package com.ftg.learn.chapter08;

/**
 * @author KangJx
 * @date 2021/7/13
 */
public class Gua {


    /**
     * 这是一个青蛙跳井的问题，的解决方案
     * @param wellHeight  井深
     * @param jumpHeight  跳的高度
     * @param down        下滑几米
     * @return
     */
    public int jumpWell(int wellHeight,int jumpHeight,int down){

        if(jumpHeight >= wellHeight){
            return 1;
        }
        if(jumpHeight <= down){
            return 0;
        }
        //次数
        int no = 1;

        //青蛙现在的位置 frogPos
        for(int frogPos = jumpHeight; frogPos < wellHeight;frogPos+=jumpHeight){
            no++;
            frogPos-=down;
        }

        return no;
    }

    public int FrogJumpWell(int wellHeight,int jumpHeight,int down){

        if(jumpHeight >= wellHeight){
            return 1;
        }
        if(jumpHeight <= down){
            return 0;
        }
        int frogPos = jumpHeight;
        int no =1;
        while (frogPos < wellHeight){
            no++;
            frogPos-=down;
            frogPos+=jumpHeight;
        }
        //表达1
        //  while(表达2){
        //      代码块
        //      exp3
        // }
        return no;
    }

    public int FrogdoWhileWell(int wellHeight,int jumpHeight,int down){

        if(jumpHeight >= wellHeight){
            return 1;
        }
        if(jumpHeight <= down){
            return 0;
        }
        int no = 0;
        int frogpostion = 0;
        do{
            if(no !=0){
                frogpostion-=down;
            }
            frogpostion+=jumpHeight;
            no++;
        }while (frogpostion < wellHeight);
        return no;
    }

}
